
#ifndef NETWORK_CHANNEL_H
#define	NETWORK_CHANNEL_H

#include <systemc>
#include "packet.h"

class channel_write_if 
: virtual public sc_core::sc_interface
{
public:
    
    virtual void write(const packet& pkt) = 0;
};

class channel_read_if 
: virtual public sc_core::sc_interface
{
public:
    
    virtual packet* read() = 0;
};

class network_channel 
: public sc_core::sc_module,
  public channel_write_if,
  public channel_read_if
{
public:
    
    network_channel(const sc_core::sc_module_name& name);
    virtual ~network_channel();

    void write(const packet& pkt);
    packet* read();
            
    virtual const sc_core::sc_event& default_event() const;
    void register_port(sc_core::sc_port_base& port,
                        const char* if_typename);

    static void set_error_probability(double p);
    
protected:
    
    packet *m_packet_buf;    
    sc_core::sc_event m_packet_written_evt;      

private:
    void add_noise();
    static double m_p;
};

#endif	/* NETWORK_CHANNEL_H */

